<template>
  <div id="loginBackground">
    <el-card id="loginCard">
      <h1>登陆</h1>
      <el-form :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="100px">
        <!--            用户名 -->
        <el-form-item label="用户名：" prop="loginName">
          <el-input type="text" v-model="loginForm.loginName" autocomplete="off" placeholder="请输入账号" />
        </el-form-item>
        <!--            密码-->
        <el-form-item label="密码：" prop="password">
          <el-input type="password" v-model="loginForm.password" autocomplete="off" placeholder="请输入密码" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    let validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"))
      } else {
        callback()
      }
    }
    let validateUserName = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入用户名！"))
      } else {
        callback()
      }
    }

    return {
      loginForm: {
        password: "",
        loginName: "",
      },
      rules: {
        password: [{ validator: validatePass, trigger: "blur" }],
        username: [{ validator: validateUserName, trigger: "blur" }],
      },
    }
  },
  methods: {
    async submitForm () {
      const { data: res } = await this.$http.get(`system/login`, { params: this.loginForm })
      if (res.code == 401) {
        return this.$message.error(res.message)
      }
      if (res.code == 400) {
        return this.$message.error(res.message)
      }
      if (res.code == 200) {
        this.$message.success(res.message)
        this.$router.push({ path: "/system/system_index" })
      }
      this.$router.push({ path: "/system/system_index" })
    },
  },
}
</script>

<style scoped>
#loginBackground {
  background: url("../assets/bg/101-desktop-wallpaper.png") no-repeat;
  background-position: center;
  height: 100%;
  width: 100%;
  background-size: cover;
  background-color: #b8e5f8;
  position: fixed;
}
#loginCard {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 90px auto;
  width: 50%;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
</style>